class Solution(object):
    def numRookCaptures(self, board):
        """
        :type board: List[List[str]]
        :rtype: int
        """
        m = len(board)
        n = len(board[0])
        for i in range(m):
            for j in range(n):
                if board[i][j] == 'R':
                    x = i
                    y = j
                    break
        k = 1
        count = 0
        while x + k < m:
            if board[x + k][y] == 'p':
                count += 1
                break
            else:
                if board[x + k][y] == 'B':
                    break
                else:
                    k += 1
        k = 1
        while x - k >= 0:
            if board[x - k][y] == 'p':
                count += 1
                break
            else:
                if board[x - k][y] == 'B':
                    break
                else:
                    k += 1
        k = 1
        while y + k < n:
            if board[x][y + k] == 'p':
                count += 1
                break
            else:
                if board[x][y + k] == 'B':
                    break
                else:
                    k += 1
        k = 1
        while y - k >= 0:
            if board[x][y - k] == 'p':
                count += 1
                break
            else:
                if board[x][y - k] == 'B':
                    break
                else:
                    k += 1
        return count




data = Solution()
board = [[".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", "p", ".", ".", ".", "."],
         [".", ".", ".", "R", ".", ".", ".", "p"], [".", ".", ".", ".", ".", ".", ".", "."],
         [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", "p", ".", ".", ".", "."],
         [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."]]
print(data.numRookCaptures(board))
